package com.shigen.demo.atguigu;

import java.util.concurrent.Executors;
import java.util.concurrent.LinkedBlockingQueue;
import java.util.concurrent.ThreadPoolExecutor;
import java.util.concurrent.TimeUnit;

/**
 * @author shigenfu
 * @date 2022/5/24 11:05 下午
 */
public class MyTheadPoolDemo {

  public static void main(String[] args) {
    // ExecutorService threadPool = Executors.newFixedThreadPool(5);
    // ExecutorService threadPool = Executors.newSingleThreadExecutor();
    // ExecutorService threadPool = Executors.newCachedThreadPool();
    ThreadPoolExecutor threadPool = new ThreadPoolExecutor(
        2,
        5,
        1L,
        TimeUnit.SECONDS,
        new LinkedBlockingQueue<>(3),
        Executors.defaultThreadFactory(),
        new ThreadPoolExecutor.DiscardPolicy()
    );


    // 模拟10个用户办理任务
    try {
      for (int i = 0; i < 10; i++) {
        threadPool.submit(() -> {
          System.out.println(Thread.currentThread().getName() + " 运行中");
        });
      }
    }catch (Exception e){
      e.printStackTrace();
    }finally {
      threadPool.shutdown();
    }



  }

}
